import { FlowDao } from '../dao/flow';
import { Movie } from "../model/movie";
import { Music } from "../model/music";
import { Sentence } from "../model/sentence";
import { NotFound } from "lin-mizar";

class Flow {
  static async getFlowList() {
    let flowList = await FlowDao.getFlowList();
    if (!flowList.length) {
      return flowList;
    }
    const newFlowList = [];
    for (let i = 0; i < flowList.length; i++) {
      let detail = null;
      switch (flowList[i].type) {
        case 100:
          detail = await Movie.findByPk(flowList[i].art_id);
          break;
        case 200:
          detail = await Music.findByPk(flowList[i].art_id);
          break;
        case 300:
          detail = await Sentence.findByPk(flowList[i].art_id);
          break;
        default:
          throw new NotFound();
      }
      flowList[i].setDataValue('detail', detail);
      newFlowList.push(flowList[i]);
    }
    // console.log(newFlowList)
    return newFlowList;
  }
}

export { Flow as FlowService }
